package org.blogspot.t0yv0.marcalog.util

import java.io._

sealed class EagerInputStream(s: InputStream) extends InputStream {
  private val buf = new BufferedInputStream(s, 4096);

  override def available() =
    buf.available() match {
      case 0 => {
        buf.mark(1);
        buf.read() match {
          case -1 => 0;
          case _  => {
            val n = buf.available();
            buf.reset();
            n
          }
        }
      }
      case n => n;
    }

  override def read()                                   = buf.read()
  override def read(b: Array[Byte])                     = buf.read(b)
  override def read(b: Array[Byte], off: Int, len: Int) = buf.read(b, off, len);
}
